#include "stdafx.h"
#include "Sum.h"
#include "Money.h"


Sum::Sum( const CExpressionSp& cspAugend, const CExpressionSp& cspAddend )
	: m_spAugend( cspAugend )
	, m_spAddend( cspAddend )
{}


bool Sum::operator ==( const Expression& /*cExpression*/ ) const
{
	return false;
}


ExpressionSp Sum::operator *( int iMultiplier ) const
{
	return std::make_shared<Sum>( *m_spAugend * iMultiplier, *m_spAddend * iMultiplier );
}


ExpressionSp Sum::operator +( const Expression& cAddend ) const
{
	return std::make_shared<Sum>( shared_from_this(), cAddend.shared_from_this() );
}


ExpressionSp Sum::Reduce( const Bank& cBank, const std::tstring& cstrTo ) const
{
	const auto amount(
		std::dynamic_pointer_cast<const Money>( m_spAugend->Reduce( cBank, cstrTo ) )->GetAmount()
		+ std::dynamic_pointer_cast<const Money>( m_spAddend->Reduce( cBank, cstrTo ) )->GetAmount() );
	return std::make_shared<Money>( amount, cstrTo );
}
